package com.hz.ys_stock.dao;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.hz.framework.MyInterFace.SystemInterFace;
import com.hz.framework.dao.CommonDBDao;
import com.hz.framework.dao.CommonDao;
import com.hz.framework.util.CommonFunc;
import com.hz.framework.util.DateUtil;
import com.hz.framework.util.SqlParameter;
import com.hz.ys_stock.bean.PresSupplier;
import com.hz.ys_stock.dbsql.StockSql;
import com.hz.ys_system.dao.QueryDao;

/**
 * *****************************************************************************
 *               Copyright(c) 2010 by 哈尔滨华泽数码科技有限公司.
 *                       All rights reserved.
 *******************************************************************************
 *     File Name         :  com.hz.ys_stock.dao.SupplierDao.java
 *     Description(说明)	:  供应商管理
 * -----------------------------------------------------------------------------
 *     No.        Date              Revised by           Description	  
 *     1		Jun 8, 2011				韩飞	              Created
 *****************************************************************************
 */
public class SupplierDao implements SystemInterFace{
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能:查询供应商信息
	 */
	public String SelSupplier(HttpServletRequest request){
		StringBuilder sbSQL = new StringBuilder();
		sbSQL.append(StockSql.SEL_SUPPLIER);
		
		sbSQL.append(new QueryDao().QueryInfo(request , new SqlParameter("suppliername","linkman",
				"telnumber","phone") , "like") );
		
		return sbSQL.toString();
	}
	/**
	 * @author 韩飞
	 * @time Nov 17, 2011	
	 * @param puser
	 * @return
	 * @throws Exception 
	 * 方法功能: 保存供应商信息
	 */
	public boolean DoSaveSupplier( PresSupplier supp ) throws Exception {
		boolean ins = false;
		CommonDao dbd= new CommonDao();
		if(supp!=null){
			//保存或更新 下拉选名称表
			supp.setSupplierid(CommonFunc.CreateRadom(11, 2));
			supp.setCreatetime(DateUtil.getDateTime());
			ins = dbd.insertinfor(supp);
		}
		return ins;
	}
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能: 修改供应商信息
	 */
	public boolean UpdSupplier(PresSupplier supp){
		CommonDao dbo= new CommonDao();
		return dbo.updateinfor(supp);
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @param request
	 * @return 
	 * 方法功能: 删除 供应商信息
	 */
	public boolean Del_Supplier(HttpServletRequest request){
		String sid = CommonDao.isnull(request.getParameter("sid"));
		CommonDBDao dbo= new CommonDBDao();
		return dbo.executeSQL(StockSql.DEL_SUPPLIER_INFO, new SqlParameter(sid));
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @param request
	 * @return 
	 * 方法功能: 根据 sid 查询 对应供应商信息
	 */
	public Map SelSupplier_Info(HttpServletRequest request) throws Exception {
		String sid = CommonDao.isnull(request.getParameter("sid"));
		CommonDao dbd= new CommonDao();
		return (Map)dbd.queryObjectByPS(StockSql.SEL_SUPPLIER_INFO, new SqlParameter(sid),null);
	}
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能:查询供应商信息
	 */
	public List SelSupplierList(){
		CommonDBDao dbo= new CommonDBDao();
		return dbo.DBjsonList(StockSql.SEL_SUPPLIER);
	}
}
